package actions;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DBModel;

@WebServlet
public class EventSignOffAction extends Action{
	private int eventId=-1;

	public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request,HttpServletResponse response){
		try{
			String username = request.getUserPrincipal().getName();
			eventId = Integer.parseInt(request.getParameter("id"));
			DBModel db=new DBModel();
			db.signOff(eventId,username);
			db.close();
			return new ActionForward(mapping.findForward("success").getPath()+"?id="+eventId, false);

		}catch (Exception e){
			e.printStackTrace();
			request.setAttribute("error", e.toString());
			return mapping.findForward("fail");
		}	
	}
}
